package day07;

import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Test {

	public static void main(String[] args) throws Exception {
		String name = "abc/emp.dat";
		RandomAccessFile raf = new RandomAccessFile(name, "r");

		Emp e1 = read(raf, 0);
		Emp e2 = read(raf, 1);
		System.out.println(e1);
		System.out.println(e2);

		raf.close();

	}

	public static Emp read(RandomAccessFile raf, int n) throws Exception {
		int start = n * 80;
		raf.seek(start);
		byte[] bytes = new byte[32];
		raf.read(bytes);
		String name = new String(bytes, "UTF-8").trim();

		int age = raf.readInt();

		bytes = new byte[10];
		raf.read(bytes);
		String gender = new String(bytes, "UTF-8").trim();

		int salary = raf.readInt();

		bytes = new byte[12];
		raf.read(bytes);

		SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
		String date = new String(bytes, "UTF-8").trim();
		Date hiredate = fmt.parse(date);

		return new Emp(name, age, gender, salary, hiredate);

	}

}
